home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
026-050
/
scopedisk31
/
doodle
/
doodle.bas
(
.txt
)
< prev
next >
Wrap
AmigaBASIC Source Code
|
1995-03-18
|
19KB
|
962 lines
' Doodle by Allen Wadle September 25, 1988
' 1905 Lanette
' Arlington, Tx 76010
' 817-649-0262
ON ERROR GOTO WrapUp
DEFINT a-z
BaseDir$ = "DF1:Doodle": BasicBMAP$ = "DF1:BasicBMAPS"
GOSUB Init.Libs
GOSUB InitConstant
GOSUB InitMenu
GOSUB InitFile
ON MENU GOSUB CheckMenu : MENU ON
ON MOUSE GOSUB CheckMouse : MOUSE ON
ON BREAK GOSUB IgnoreBreak: BREAK ON
Unfinished = -1: BEEP
WHILE Unfinished
SLEEP 'this program is completely event driven
WEND
WrapUp:
MENU OFF: MOUSE OFF
SCREEN CLOSE 1
WINDOW CLOSE 1
WINDOW 1,,,,-1
MENU RESET
CLS
ON ERROR GOTO 0
END
InitConstant:
depth=3: xmin=0: ymin=0: xmax=640: ymax=200
smax=10000: DIM RegionArray%(smax/2) 'alloc 10k bytes for cut/paste
MaxTool=8: DIM ToolName$(MaxTool)
MaxReg=4: DIM RegionTool$(MaxReg)
CurrentColor=1
MaxColor = 2^depth - 1: DIM ColorName$(MaxColor)
SCREEN 1,xmax,ymax,depth,2
WINDOW 1,"Doodle by Allen Wadle",,21,1
ColorName$(0)=" white ": PALETTE 0,1,1,1
ColorName$(1)=" blue ": PALETTE 1,0,0.3,0.6
ColorName$(2)=" black ": PALETTE 2,0,0,0.1
ColorName$(3)=" orange ": PALETTE 3,1,0.5,0
ColorName$(4)=" red ": PALETTE 4,0.93,0.2,0
ColorName$(5)=" yellow ": PALETTE 5,1,1,0.13
ColorName$(6)=" green ": PALETTE 6,0.33,0.87,0
ColorName$(7)=" gray ": PALETTE 7,0.73,0.73,0.73
MaxFont=3: DIM FontName$(MaxFont), FontSize&(MaxFont)
FontName$(0)="topaz" : FontSize&(0)=11
FontName$(1)="ruby" : FontSize&(1)=15
FontName$(2)="garnet" : FontSize&(2)=16
FontName$(3)="sapphire": FontSize&(3)=19
RETURN
InitFile:
CALL Interact("Name for picture?",FileName$)
WINDOW CLOSE 1: WINDOW 1,FileName$,,21,1
CurrentX=640:CurrentY=200
menuitem=1: GOSUB ToolsMenu: menuitem=2: GOSUB ColorMenu
menuitem=3: GOSUB FontMenu
menuitem=0: GOSUB RegionMenu
RETURN
InitMenu:
MENU 1,0,1,"File"
MENU 1,1,1,"Directory"
MENU 1,2,1,"Clear"
MENU 1,3,1,"Print"
MENU 1,4,1,"Save"
MENU 1,5,1,"Load"
MENU 1,6,1,"Quit"
MENU 2,0,1,"Tools"
ToolName$(1)="Pen "
ToolName$(2)="Line "
ToolName$(3)="Oval "
ToolName$(4)="Rectangle"
ToolName$(5)="Diamond "
ToolName$(6)="Text "
ToolName$(7)="Eraser "
ToolName$(8)="Paint "
FOR i=1 TO MaxTool: MENU 2,i,1," "+ToolName$(i): NEXT
MENU 3,0,1,"Colors"
FOR i=0 TO MaxColor: MENU 3,i+1,1,ColorName$(i): NEXT
MENU 4,0,1,"Fonts"
FOR i=0 TO MaxFont: MENU 4,i+1,1," "+FontName$(i): NEXT
MENU 5,0,1,"Region"
RegionTool$(1)="Clear Reg"
RegionTool$(2)="Memorize "
RegionTool$(3)="Paste "
RegionTool$(4)="Combine "
FOR i=1 TO MaxReg: MENU 5,i,1," "+RegionTool$(i): NEXT
MENU 6,0,1,""
RETURN
CheckMenu:
MenuId=MENU(0)
menuitem=MENU(1)
ON MenuId GOTO FileMenu,ToolsMenu,ColorMenu,FontMenu,RegionMenu
CheckMouse:
GetCurrentXY
StartY=CurrentY
StartX=CurrentX
IF RegionMode<>0 THEN
ON RegionMode GOSUB ClearRegion,MemorizeRegion,PasteRegion,PasteRegion
ELSE
ON ToolMode GOSUB Pen,DoLine,DoCircle,DoRectangle,DoDiamond,DoText,DoErase,DoPaint
END IF
RETURN
DoText:
WHILE MOUSE(0)<>0
GetCurrentXY
col = 1 + CurrentX/8
row = 1 + CurrentY/8
InvertVideo
LOCATE row,col: PRINT "?";
LOCATE row,col: PRINT "?";
NormalVideo
WEND
COLOR CurrentColor
BEEP: LOCATE row,col
CALL DiskFont( FontName$(Fontnum), FontSize&(Fontnum) )
GetText:
a$=INKEY$
IF a$<>CHR$(13) THEN
PRINT a$;
GOTO GetText
END IF
CALL DiskFont( "topaz", 8 )
RETURN
DoLine:
WHILE MOUSE(0)<>0
GetCurrentXY
InvertVideo
LINE (StartX,StartY)-(CurrentX,CurrentY) 'draw line
LINE (StartX,StartY)-(CurrentX,CurrentY) 'erase line
NormalVideo
WEND
LINE (StartX,StartY)-(CurrentX,CurrentY),CurrentColor
RETURN
Pen:
GetCurrentXY
PSET (CurrentX,CurrentY),CurrentColor
WHILE MOUSE(0)<>0
GetCurrentXY
LINE -(CurrentX,CurrentY),CurrentColor
WEND
RETURN
DoCircle:
WHILE MOUSE(0)<>0
GetCurrentXY
CenterX=(StartX+CurrentX)/2
CenterY=(CurrentY+StartY)/2
RadiusX=ABS(CurrentX-StartX)/2: IF RadiusX=0 THEN RadiusX=1
RadiusY=ABS(CurrentY-StartY)/2: IF RadiusY=0 THEN RadiusY=1
Aspect!=ABS(RadiusY/RadiusX)
IF RadiusX < RadiusY THEN RadiusX=RadiusY
InvertVideo
FOR i = 1 TO 2
CIRCLE (CenterX,CenterY),RadiusX,CurrentColor,,,Aspect!
NEXT
NormalVideo
WEND
CIRCLE (CenterX,CenterY),RadiusX,CurrentColor,,,Aspect!
RETURN
DoRectangle:
WHILE MOUSE(0)<>0
GetCurrentXY
InvertVideo
FOR i = 1 TO 2
LINE (StartX,StartY)-(CurrentX,CurrentY),CurrentColor,b
NEXT
NormalVideo
WEND
LINE (StartX,StartY)-(CurrentX,CurrentY),CurrentColor,b
RETURN
DoDiamond:
WHILE MOUSE(0)<>0
GetCurrentXY
CenterX=(StartX+CurrentX)/2
CenterY=(CurrentY+StartY)/2
InvertVideo
FOR i = 1 TO 2
LINE (CenterX,StartY)-(CurrentX,CenterY),CurrentColor
LINE (CurrentX,CenterY)-(CenterX,CurrentY),CurrentColor
LINE (CenterX,CurrentY)-(StartX,CenterY),CurrentColor
LINE (StartX,CenterY)-(CenterX,StartY),CurrentColor
NEXT
NormalVideo
WEND
LINE (CenterX,StartY)-(CurrentX,CenterY),CurrentColor
LINE (CurrentX,CenterY)-(CenterX,CurrentY),CurrentColor
LINE (CenterX,CurrentY)-(StartX,CenterY),CurrentColor
LINE (StartX,CenterY)-(CenterX,StartY),CurrentColor
RETURN
DoErase:
WHILE MOUSE(0)<>0
GetCurrentXY
LINE (CurrentX-5,CurrentY-3)-(CurrentX,CurrentY),1,bf
LINE (CurrentX-5,CurrentY-3)-(CurrentX,CurrentY),0,bf
WEND
RETURN
DoPaint:
PAINT (CurrentX, CurrentY),CurrentColor
ToolMode=OldTool: GOSUB ShowTool
RETURN
ToolsMenu:
OldTool=ToolMode: ToolMode=menuitem: RegionMode=0
ShowTool:
FOR i=1 TO MaxTool: MENU 2,i,1: NEXT
FOR i=1 TO MaxReg: MENU 5,i,1: NEXT
IF RegionMode=0 THEN
MENU 2,ToolMode,2
LOCATE 1,16: COLOR 1: PRINT ToolName$(ToolMode);
ELSE
MENU 5,RegionMode,2
LOCATE 1,16: COLOR 1: PRINT RegionTool$(RegionMode)
END IF
RETURN
FontMenu:
Fontnum=menuitem-1
FOR i=1 TO MaxFont+1: MENU 4,i,1: NEXT: MENU 4,menuitem,2
RETURN
ColorMenu:
CurrentColor=menuitem-1
COLOR CurrentColor
FOR i=1 TO MaxColor+1: MENU 3,i,1: NEXT: MENU 3,menuitem,2
ColorBar:
x=20: dx=10: dy=5: xc=2*dy: yc=dy/2
CIRCLE (xc,yc),dy,CurrentColor: PAINT (xc,yc)
FOR i=0 TO MaxColor
LINE (x,0)-(x+dx,dy),i,bf
LINE (x,0)-(x+dx,dy),1,b
x=x+dx
NEXT i
RETURN
RegionMenu:
RegionMode = menuitem
GOSUB ShowTool
RETURN
ClearRegion:
WHILE MOUSE(0)<>0
GetCurrentXY
InvertVideo
FOR i = 1 TO 2
LINE (StartX,StartY)-(CurrentX,CurrentY),CurrentColor,b
NEXT
NormalVideo
WEND
LINE (StartX,StartY)-(CurrentX,CurrentY),0,bf
RETURN
MemorizeRegion:
WHILE MOUSE(0)<>0
GetCurrentXY
EndX=CurrentX
term=INT((EndX-StartX+16)/16)
IF term=0 THEN term=1
EndYmax = (smax-6)/(2*depth*term)+StartY-1
IF CurrentY<=EndYmax THEN
EndY=CurrentY
ELSE
EndY=EndYmax
END IF
InvertVideo
FOR i = 1 TO 2
LINE (StartX,StartY)-(EndX,EndY),CurrentColor,b
NEXT
NormalVideo
WEND
GET (StartX,StartY)-(EndX,EndY),RegionArray
delXreg=EndX-StartX: delYreg=EndY-StartY
menuitem=0: GOSUB RegionMenu
BEEP
RETURN
PasteRegion:
WHILE MOUSE(0)<>0
GetCurrentXY
EndX=CurrentX+delXreg: EndY=CurrentY+delYreg
InvertVideo
FOR i = 1 TO 2
LINE (CurrentX,CurrentY)-(EndX,EndY),CurrentColor,b
NEXT
NormalVideo
WEND
IF RegionMode=4 THEN
PUT (CurrentX,CurrentY),RegionArray,OR
ELSE
PUT (CurrentX,CurrentY),RegionArray,PSET
END IF
RETURN
FileMenu:
ON menuitem GOSUB Directory,InitFile,PrintScreen,SaveFile,LoadFile,Quit
RETURN
Directory:
WINDOW 2,"Directory of "+BaseDir$,,0
FILES
INPUT "<< RETURN >>";response$
WINDOW CLOSE 2: WINDOW 1
RETURN
PrintScreen:
ScreenDump: BEEP
RETURN
SaveFile:
CALL Interact( "Save File Name?", FileName$ )
OPEN FileName$ FOR OUTPUT AS #1: CLOSE #1
CALL Save.Load.ILBM( "save", FileName$ )
BEEP
RETURN
LoadFile:
CALL Interact( "Load File Name?", FileName$ )
CALL Save.Load.ILBM( "load", FileName$ )
BEEP
RETURN
Quit:
Unfinished=0
RETURN
SUB GetCurrentXY STATIC
SHARED CurrentX,CurrentY
dummy=MOUSE(0)
CurrentX=MOUSE(1)
CurrentY=MOUSE(2)
END SUB
SUB InvertVideo STATIC
CALL SetDrMd& (WINDOW(8),3)
END SUB
SUB NormalVideo STATIC
CALL SetDrMd& (WINDOW(8),1)
END SUB
IgnoreBreak:
RETURN
'__________________________________________________________________________
'
' Routines to Save, Load, & Print Amiga Screens & change fonts
'
' GOSUB Init.Libs
' CALL Save.Load.ILBM( mode$, filename$ ), where mode$="save"/"load"
' Call ScreenDump
' Call DiskFont( fontname$, height& )
'___________________________________________________________________________
SUB DiskFont( FontName$, height& ) STATIC
textAttr&(0)=SADD(FontName$+".font"+CHR$(0))
textAttr&(1)=height&*65536
FontPtr&=OpenDiskFont&(VARPTR(textAttr&(0)))
IF FontPtr& THEN SetFont& WINDOW(8),FontPtr&
END SUB
SUB Interact( prompt$, response$ ) STATIC
WINDOW 2,"Interaction Window",,0
LINE (0,0)-(620,190),1,bf
LINE (20,10)-(600,180),2,bf
LINE (40,20)-(580,170),3,bf
LINE (60,30)-(560,160),0,bf
LOCATE 10,20: PRINT prompt$;
LOCATE 12,20: INPUT response$
WINDOW CLOSE 2: WINDOW 1
END SUB
Init.Libs:
REM - Functions from dos.library
DECLARE FUNCTION xOpen& LIBRARY
DECLARE FUNCTION xRead& LIBRARY
DECLARE FUNCTION xWrite& LIBRARY
REM - xClose returns no value
REM - Functions from exec.library
DECLARE FUNCTION AllocMem&() LIBRARY
REM - FreeMem returns no value
DECLARE FUNCTION AllocSignal%() LIBRARY
DECLARE FUNCTION FindTask&() LIBRARY
DECLARE FUNCTION DoIO&() LIBRARY
DECLARE FUNCTION OpenDevice& LIBRARY
REM - Functions from diskfont.library
DECLARE FUNCTION OpenDiskFont& LIBRARY
CHDIR BasicBMAP$
LIBRARY "dos.library"
LIBRARY "exec.library"
LIBRARY "graphics.library"
LIBRARY "diskfont.library"
CHDIR BaseDir$
RETURN
SUB Save.Load.ILBM( mode$,ILBMname$) STATIC
REM No cycling info here
ccrtDir%=0
ccrtStart%=0
ccrtEnd%=0
ccrtSecs&=0
ccrtMics&=0
IF mode$="save" THEN GOSUB SaveILBM
IF mode$="load" THEN GOSUB LoadILBM
EXIT SUB
SaveILBM:
REM - Saves current window's screen
REM - as an IFF ILBM file with a
REM - Graphicraft CCRT cycling chunk.
REM - Requires the following variables
REM - to have been initialized:
REM - ILBMname$ (ILBM filespec)
REM - Also, cycling variables
REM - ccrtDir% (1,-1, or 0 = none)
REM - ccrtStart% (low cycle reg)
REM - ccrtEnd% (high cycle reg)
REM - ccrtSecs& (cycle time in seconds)
REM - ccrtMics& (cycle time in microseconds)
REM
REM - init variables
F$ = ILBMname$
fHandle& = 0
mybuf& = 0
FileName$ = F$ + CHR$(0)
fHandle& = xOpen&(SADD(FileName$),1006)
IF fHandle& = 0 THEN
saveError$ = "Can't open output file"
GOTO Scleanup
END IF
REM - Alloc ram for work buffers
ClearPublic& = 65537
mybufsize& = 120
mybuf& = AllocMem&(mybufsize&,ClearPublic&)
IF mybuf& = 0 THEN
saveError$ = "Can't alloc buffer"
GOTO Scleanup
END IF
cbuf& = mybuf&
REM - Get addresses of screen structures
GOSUB GetScrAddrs
zero& = 0
pad% = 0
Aspect% = &Ha0b
REM - Compute chunk sizes
BMHDsize& = 20
CMAPsize& = (2^scrDepth%) * 3
CAMGsize& = 4
CCRTsize& = 14
BODYsize& = (scrWidth%/8) * scrHeight% * scrDepth%
REM - FORMsize& = Chunk sizes + 8 bytes per Chunk header + "ILBM"
FORMsize& = BMHDsize&+CMAPsize&+CAMGsize&+CCRTsize&+BODYsize&+44
REM - Write FORM header
tt$ = "FORM"
wLen& = xWrite&(fHandle&,SADD(tt$),4)
wLen& = xWrite&(fHandle&,VARPTR(FORMsize&),4)
tt$ = "ILBM"
wLen& = xWrite&(fHandle&,SADD(tt$),4)
IF wLen& <= 0 THEN
saveError$ = "Error writing FORM header"
GOTO Scleanup
END IF
REM - Write out BMHD chunk
tt$ = "BMHD"
wLen& = xWrite&(fHandle&,SADD(tt$),4)
wLen& = xWrite&(fHandle&,VARPTR(BMHDsize&),4)
wLen& = xWrite&(fHandle&,VARPTR(scrWidth%),2)
wLen& = xWrite&(fHandle&,VARPTR(scrHeight%),2)
wLen& = xWrite&(fHandle&,VARPTR(zero&),4)
temp% = (256 * scrDepth%)
wLen& = xWrite&(fHandle&,VARPTR(temp%),2)
wLen& = xWrite&(fHandle&,VARPTR(zero&),4)
wLen& = xWrite&(fHandle&,VARPTR(Aspect%),2)
wLen& = xWrite&(fHandle&,VARPTR(scrWidth%),2)
wLen& = xWrite&(fHandle&,VARPTR(scrHeight%),2)
IF wLen& <= 0 THEN
saveError$ = "Error writing BMHD"
GOTO Scleanup
END IF
REM - Write CMAP chunk
tt$ = "CMAP"
wLen& = xWrite&(fHandle&,SADD(tt$),4)
wLen& = xWrite&(fHandle&,VARPTR(CMAPsize&),4)
REM - Build IFF ColorMap
FOR kk = 0 TO nColors% - 1
regTemp% = PEEKW(colorTab& + (2*kk))
POKE(cbuf&+(kk*3)),(regTemp% AND &Hf00) / 16
POKE(cbuf&+(kk*3)+1),(regTemp% AND &Hf0)
POKE(cbuf&+(kk*3)+2),(regTemp% AND &Hf) * 16
NEXT
wLen& = xWrite&(fHandle&,cbuf&,CMAPsize&)
IF wLen& <= 0 THEN
saveError$ = "Error writing CMAP"
GOTO Scleanup
END IF
REM - Write CAMG chunk
tt$ = "CAMG"
wLen& = xWrite&(fHandle&,SADD(tt$),4)
wLen& = xWrite&(fHandle&,VARPTR(CAMGsize&),4)
vpModes& = PEEKW(sViewPort& + 32)
wLen& = xWrite&(fHandle&,VARPTR(vpModes&),4)
IF wLen& <= 0 THEN
saveError$ = "Error writing CAMG"
GOTO Scleanup
END IF
REM - Write CCRT chunk
tt$ = "CCRT"
wLen& = xWrite&(fHandle&,SADD(tt$),4)
wLen& = xWrite&(fHandle&,VARPTR(CCRTsize&),4)
wLen& = xWrite&(fHandle&,VARPTR(ccrtDir%),2)
temp% = (256*ccrtStart%) + ccrtEnd%
wLen& = xWrite&(fHandle&,VARPTR(temp%),2)
wLen& = xWrite&(fHandle&,VARPTR(ccrtSecs&),4)
wLen& = xWrite&(fHandle&,VARPTR(ccrtMics&),4)
wLen& = xWrite&(fHandle&,VARPTR(pad%),2)
IF wLen& <= 0 THEN
saveError$ = "Error writing CCRT"
GOTO Scleanup
END IF
REM - Write BODY chunk
tt$ = "BODY"
wLen& = xWrite&(fHandle&,SADD(tt$),4)
wLen& = xWrite&(fHandle&,VARPTR(BODYsize&),4)
scrRowBytes% = scrWidth% / 8
FOR rr = 0 TO scrHeight% -1
FOR pp = 0 TO scrDepth% -1
scrRow& = bPlane&(pp)+(rr*scrRowBytes%)
wLen& = xWrite&(fHandle&,scrRow&,scrRowBytes%)
IF wLen& <= 0 THEN
saveError$ = "Error writing BODY"
GOTO Scleanup
END IF
NEXT
NEXT
saveError$ = ""
Scleanup:
ERASE bPlane&
IF fHandle& <> 0 THEN CALL xClose&(fHandle&)
IF mybuf& <> 0 THEN CALL FreeMem&(mybuf&,mybufsize&)
RETURN
GetScrAddrs:
REM - Get addresses of screen structures
sWindow& = WINDOW(7)
sScreen& = PEEKL(sWindow& + 46)
sViewPort& = sScreen& + 44
sRastPort& = sScreen& + 84
sColorMap& = PEEKL(sViewPort& + 4)
colorTab& = PEEKL(sColorMap& + 4)
sBitMap& = PEEKL(sRastPort& + 4)
REM - Get screen parameters
scrWidth% = PEEKW(sScreen& + 12)
scrHeight% = PEEKW(sScreen& + 14)
scrDepth% = PEEK(sBitMap& + 5)
nColors% = 2^scrDepth%
DIM bPlane&(scrDepth%-1)
REM - Get addresses of Bit Planes
FOR kk = 0 TO scrDepth% - 1
bPlane&(kk) = PEEKL(sBitMap&+8+(kk*4))
NEXT
RETURN
LoadILBM:
REM - Requires the following variables
REM - to have been initialized:
REM - ILBMname$ (IFF filename)
REM - init variables
F$ = ILBMname$
fHandle& = 0
mybuf& = 0
foundBMHD = 0
foundCMAP = 0
foundCAMG = 0
foundCCRT = 0
foundBODY = 0
REM - From include/libraries/dos.h
REM - MODE_NEWFILE = 1006
REM - MODE_OLDFILE = 1005
FileName$ = F$ + CHR$(0)
fHandle& = xOpen&(SADD(FileName$),1005)
IF fHandle& = 0 THEN
loadError$ = "Can't open/find pic file"
GOTO Lcleanup
END IF
REM - Alloc ram for work buffers
ClearPublic& = 65537
mybufsize& = 360
mybuf& = AllocMem&(mybufsize&,ClearPublic&)
IF mybuf& = 0 THEN
loadError$ = "Can't alloc buffer"
GOTO Lcleanup
END IF
inbuf& = mybuf&
cbuf& = mybuf& + 120
ctab& = mybuf& + 240
REM - Should read FORMnnnnILBM
rLen& = xRead&(fHandle&,inbuf&,12)
tt$ = ""
FOR kk = 8 TO 11
tt% = PEEK(inbuf& + kk)
tt$ = tt$ + CHR$(tt%)
NEXT
IF tt$ <> "ILBM" THEN
loadError$ = "Not standard ILBM pic file"
GOTO Lcleanup
END IF
REM - Read ILBM chunks
ChunkLoop:
REM - Get Chunk name/length
rLen& = xRead&(fHandle&,inbuf&,8)
icLen& = PEEKL(inbuf& + 4)
tt$ = ""
FOR kk = 0 TO 3
tt% = PEEK(inbuf& + kk)
tt$ = tt$ + CHR$(tt%)
NEXT
IF tt$ = "BMHD" THEN 'BitMap header
foundBMHD = 1
rLen& = xRead&(fHandle&,inbuf&,icLen&)
iWidth% = PEEKW(inbuf&)
iHeight% = PEEKW(inbuf& + 2)
iDepth% = PEEK(inbuf& + 8)
iCompr% = PEEK(inbuf& + 10)
scrWidth% = PEEKW(inbuf& + 16)
scrHeight% = PEEKW(inbuf& + 18)
iRowBytes% = iWidth% /8
scrRowBytes% = scrWidth% / 8
nColors% = 2^(iDepth%)
REM - Enough free ram to display ?
AvailRam& = FRE(-1)
NeededRam& = ((scrWidth%/8)*scrHeight%*(iDepth%+1))+5000
IF AvailRam& < NeededRam& THEN
loadError$ = "Not enough free ram"
GOTO Lcleanup
END IF
REM - Get addresses of structures
GOSUB GetScrAddrs
REM - Black out screen
REM CALL LoadRGB4&(sViewPort&,ctab&,nColors%)
ELSEIF tt$ = "CMAP" THEN 'ColorMap
foundCMAP = 1
rLen& = xRead&(fHandle&,cbuf&,icLen&)
REM - Build Color Table
FOR kk = 0 TO nColors% - 1
red% = PEEK(cbuf&+(kk*3))
gre% = PEEK(cbuf&+(kk*3)+1)
blu% = PEEK(cbuf&+(kk*3)+2)
regTemp% = (red%*16)+(gre%)+(blu%/16)
POKEW(ctab&+(2*kk)),regTemp%
NEXT
ELSEIF tt$ = "CAMG" THEN 'Amiga ViewPort Modes
foundCAMG = 1
rLen& = xRead&(fHandle&,inbuf&,icLen&)
camgModes& = PEEKL(inbuf&)
ELSEIF tt$ = "CCRT" THEN 'Graphicraft color cycle info
foundCCRT = 1
rLen& = xRead&(fHandle&,inbuf&,icLen&)
ccrtDir% = PEEKW(inbuf&)
ccrtStart% = PEEK(inbuf& + 2)
ccrtEnd% = PEEK(inbuf& + 3)
ccrtSecs& = PEEKL(inbuf& + 4)
ccrtMics& = PEEKL(inbuf& + 8)
ELSEIF tt$ = "BODY" THEN 'BitMap
foundBODY = 1
IF iCompr% = 0 THEN 'no compression
FOR rr = 0 TO iHeight% -1
FOR pp = 0 TO iDepth% -1
scrRow& = bPlane&(pp)+(rr*scrRowBytes%)
rLen& = xRead&(fHandle&,scrRow&,iRowBytes%)
NEXT
NEXT
ELSEIF iCompr% = 1 THEN 'cmpByteRun1
FOR rr = 0 TO iHeight% -1
FOR pp = 0 TO iDepth% -1
scrRow& = bPlane&(pp)+(rr*scrRowBytes%)
bCnt% = 0
WHILE (bCnt% < iRowBytes%)
rLen& = xRead&(fHandle&,inbuf&,1)
inCode% = PEEK(inbuf&)
IF inCode% < 128 THEN
rLen& = xRead&(fHandle&,scrRow& + bCnt%, inCode%+1)
bCnt% = bCnt% + inCode% + 1
ELSEIF inCode% > 128 THEN
rLen& = xRead&(fHandle&,inbuf&,1)
inByte% = PEEK(inbuf&)
FOR kk = bCnt% TO bCnt% + 257 - inCode%
POKE(scrRow&+kk),inByte%
NEXT
bCnt% = bCnt% + 257 - inCode%
END IF
WEND
NEXT
NEXT
ELSE
loadError$ = "Unknown compression algorithm"
GOTO Lcleanup
END IF
ELSE
REM - Reading unknown chunk
FOR kk = 1 TO icLen&
rLen& = xRead&(fHandle&,inbuf&,1)
NEXT
REM - If odd length, read 1 more byte
IF (icLen& OR 1) = icLen& THEN
rLen& = xRead&(fHandle&,inbuf&,1)
END IF
END IF
REM - Done if got all chunks
IF foundBMHD AND foundCMAP AND foundBODY THEN
GOTO GoodLoad
END IF
REM - Good read, get next chunk
IF rLen& > 0 THEN GOTO ChunkLoop
IF rLen& < 0 THEN 'Read error
loadError$ = "Read error"
GOTO Lcleanup
END IF
REM - rLen& = 0 means EOF
IF (foundBMHD=0) OR (foundBODY=0) OR (foundCMAP=0) THEN
loadError$ = "Needed ILBM chunks not found"
GOTO Lcleanup
END IF
GoodLoad:
loadError$ = ""
REM Load proper Colors
IF foundCMAP THEN
CALL LoadRGB4&(sViewPort&,ctab&,nColors%)
END IF
Lcleanup:
ERASE bPlane&
IF fHandle& <> 0 THEN CALL xClose&(fHandle&)
IF mybuf& <> 0 THEN CALL FreeMem&(mybuf&,mybufsize&)
RETURN
END SUB
SUB ScreenDump STATIC
REM Get addresses of the structures
sWindow& = WINDOW(7)
sScreen& = PEEKL(sWindow& + 46)
sViewPort& = sScreen& + 44
sRastPort& = sScreen& + 84
sColorMap& = PEEKL(sViewPort& + 4)
REM Get Screen width, height, modes
maxWidth% = PEEKW(sScreen& + 12)
maxHeight% = PEEKW(sScreen& + 14)
viewModes% = PEEKW(sViewPort& + 32)
REM Set up parameters for dump command
command% = 11 'Printer command number
srcX% = 0 'Send whole screen
srcY% = 0
srcWidth% = maxWidth%
srcHeight% = maxHeight%
destRows& = 0 'Dump will compute
destCols& = 0
special% = &H84 'FullCol | Aspect
REM *** CreatePort ***
sigBit% = AllocSignal%(-1)
ClearPublic& = 65537
msgPort& = AllocMem&(40,ClearPublic&)
IF msgPort& = 0 THEN
CALL Interact( "Can't allocate msgPort", dummy$ )
GOTO cleanup4
END IF
POKE(msgPort& + 8), 4 'Type=NT_MSGPORT
POKE(msgPort& + 9), 0 'Priority 0
portName$ = "MyPrtPort"+CHR$(0)
POKEL(msgPort& + 10), SADD(portName$)
POKE(msgPort& + 14), 0 'Flags
POKE(msgPort& + 15), sigBit%
sigTask& = FindTask&(0)
POKEL(msgPort& + 16), sigTask&
CALL AddPort#(msgPort&) 'Add the port
REM *** CreatExtIO ***
ioRequest& = AllocMem&(64,ClearPublic&)
IF ioRequest& = 0 THEN
CALL Interact( "Can't allocate ioRequest", dummy$ )
GOTO cleanup3
END IF
POKE(ioRequest& + 8),5 'Type=NT_MESSAGE
POKE(ioRequest& + 9),0 'Priority 0
POKEL(ioRequest& + 14), msgPort&
REM *** Open the Printer Device ***
devName$ = "printer.device"+CHR$(0)
pError& = OpenDevice&(SADD(devName$),0,ioRequest&,0)
IF pError& <> 0 THEN
CALL Interact( "Can't open printer", dummy$ )
GOTO cleanup2
END IF
REM *** Dump the RastPort ***
POKEW(ioRequest& + 28), command%
POKEL(ioRequest& + 32), sRastPort&
POKEL(ioRequest& + 36), sColorMap&
POKEL(ioRequest& + 40), viewModes%
POKEW(ioRequest& + 44), srcX%
POKEW(ioRequest& + 46), srcY%
POKEW(ioRequest& + 48), srcWidth%
POKEW(ioRequest& + 50), srcHeight%
POKEL(ioRequest& + 52), destCols&
POKEL(ioRequest& + 56), destRows&
POKEW(ioRequest& + 60), special%
ioError& = DoIO&(ioRequest&)
IF ioError& <> 0 THEN
CALL Interact( "DumpRPort error", dummy$ )
GOTO cleanup1
END IF
cleanup1:
REM *** Close Printer Device ***
CALL CloseDevice#(ioRequest&)
cleanup2:
REM *** DeleteExtIO ***
POKE(ioRequest& + 8), &Hff
POKEL(ioRequest& + 20), -1
POKEL(ioRequest& + 24), -1
CALL FreeMem&(ioRequest&,64)
cleanup3:
REM *** DeletePort ***
CALL RemPort#(msgPort&)
POKE(msgPort& + 8), &Hff
POKEL(msgPort& + 20), -1
CALL FreeSignal#(sigBit%)
CALL FreeMem&(msgPort&,40)
cleanup4:
END SUB